package gui.commands.classDiagramCommands;

import data.DataVector;
import data.classDiagram.Entity;
import gui.commands.ICommand;

/**
 * User: Szymon Kudzia
 * Date: 10.05.13
 * Time: 15:47
 */
public class DeleteImplementedInterfaceCommand implements ICommand {
	protected Entity entity;
	protected String impInterface;

	public DeleteImplementedInterfaceCommand(String impInterface) {
		this.impInterface = impInterface;
	}

	@Override
	public void execute() {
		if ((entity = DataVector.getInstance().getActiveEntity()) != null) {
			entity.getInterfacesImplemented().remove(impInterface);
			refresh();
		}
	}

	@Override
	public void undo() {
		entity.getInterfacesImplemented().add(impInterface);
		refresh();
	}

	@Override
	public void redo() {
		entity.getInterfacesImplemented().remove(impInterface);
		refresh();
	}

	private void refresh() {
		DataVector.getInstance().refresh();
	}
}
